package DControl;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DButton extends DComponent implements DMouseListener{
	
	 public DButton()
	 {
		 init();
		 setResponseRect(x, y, x + width, y + height);
		 
	 }
	 
	 public DButton(String text)
	 {
		 init();
		 this.text = text;
		 setResponseRect(x, y, x + width, y + height);
	 }
	 
	 public DButton(int x,int y,String text)
	 {
		 init();
		 this.x = x;
		 this.y = y;
		 this.text = text;
		 setResponseRect(x, y, x + width, y + height);
	 }
	 
	 public void init()
	 {
		 x = 0;
		 y = 0;
		 width = 70;
		 height = 30;
		 arcWidth =6;
		 arcHeight = 6;
		 text = "Button";
		 color = Color.LIGHT_GRAY;
		 rasied = true;
		 Class = "DButton";
		 this.color = Color.pink;
	 }
	 
	 public void paintComponent(Graphics g)
	 {
		 g.setColor(Color.black.gray);
		 g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
		 g.setColor(color);
		 g.fill3DRect(x+2, y+2, width-3, height-3, rasied);
		 g.setColor(Color.black);
		 g.drawString(text,x + (width/2 - text.length()*6/2), y + height/2 + 5);
		 g.setColor(color);
	 }
	 
	 public void mouseEntered(MouseEvent e){}
   	 
   	 public void mouseExited(MouseEvent e){}
   	 
   	 public void mousePressed(MouseEvent e)
   	 {
   		 if(listener != null)
   		 {
   			 listener.mousePressed(e);
   		 }
   		 rasied = false;
   		 repaint();
   	 }
   	 
   	 public void mouseReleased(MouseEvent e)
   	 {
   		 rasied = true;
   		 repaint();
   	 }
   	 
   	 public void mouseClicked(MouseEvent e)
   	 {
   		 
   	 }
		 
	 
	 
}